package com.lanou3g.code0515.study;

import org.junit.Test;

import java.util.UUID;

/**
 * Created by dllo on 18/5/15.
 */
public class TestUUID {
    @Test
    public void fun(){
        String uuid = UUID.randomUUID().toString();
        System.out.println(uuid);
    }
    public static String getRandomString(){
        String uuid
                =UUID.randomUUID()
                .toString()//转成字符串
                .replace("-","")//去掉-
                .toUpperCase();//转成大写字母
        return uuid;
    }
//aaa.png=>uuid.png
    public  static String handleFileName(String filename){
        String name =getRandomString();//获取uuid
        //找到最后一个.的下标
        int lastIndex = filename.lastIndexOf(".");
        String expand= filename
                .substring(lastIndex,filename.length());
        return name+expand;//拼接成新的文件名
    }
    @Test
    public void test01(){
        String newName =handleFileName("aaa.png");
        System.out.println(newName);
    }

}
